#!/usr/bin/env osascript
(*

  Copyright (c) 2021-2024: Jacob.Lundqvist@gmail.com
  License: MIT

  Part of https://github.com/jaclu/tmux-menus

  Returns the current playing song in Spotify for MacOS

*)


tell application "Spotify"
  if it is running then
    if player state is playing then
      set track_name to name of current track
      set artist_name to artist of current track
      set album_name to album of current track
      if artist_name > 0
        -- If the track has an artist set and is therefore most likely a song
        -- rather than an advert
        track_name & " - " & artist_name & " - " & album_name
      else
        -- If the track doesn't have an artist set and is therefore most likely
        -- an advert rather than a song
        "~ " & track_name
      end if
    end if
  end if
end tell
